<template>
  <div>
    <div class="dl">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          label="账号"
          placeholder="账号"
          :rules="[{ required: true, message: '请填写您的账号' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >提交</van-button
          >
        </div>
      </van-form>
      <a @click="register">没有账号？点击注册</a>
    </div>
  </div>
</template>

<script>
import { Notify } from 'vant';
export default {
  props: {},
  data() {
    return {
      username: "",
      password: "",
    };
  },
  computed: {},
  created() {},
  mounted() {},
  watch: {},
  methods: {
    onSubmit(values) { // 登录提交
      console.log(values);
      let verify = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/
      if(verify.test(values.username)){
         this.$api.login({phone: values.username,password:values.password}).then((res)=>{
            localStorage.setItem('userinfo',JSON.stringify(res.data.list))
            this.$router.push('/')
            Notify({ type: 'success', message: '登陆成功' });
         })
      }else{
         Notify({ type: 'warning', message: '请您输入正确的账号' });
         return
      }
    },
    register(){ // 去注册
      this.$router.push('/register')
    }
  },
  components: {},
};
</script>

<style scoped lang="less">
.dl {
  margin: 50% auto;
}
a{
   font-size: 30px;
   color: #39f;
}
</style>
